package graphics.synchronize;
import graphics.objects.GraphicsObject;
import network.byteConversions.ByteArrayReader;
import network.byteConversions.ByteArrayWriter;
import network.byteConversions.ByteMapper;
public class SyncGraphicsObject {
	private static ByteMapper bmap;
	private static ByteArrayReader read;
	private static ByteArrayWriter write;
	public static void init() {
		bmap = new ByteMapper();
		bmap.mapVar("pos", 'P');
		bmap.mapVar("angle", 'F');
		bmap.mapVar("colR", 'F');
		bmap.mapVar("colG", 'F');
		bmap.mapVar("colB", 'F');
		bmap.mapVar("colA", 'F');
		read = new ByteArrayReader(bmap);
		write = new ByteArrayWriter(bmap);
	}
	public static byte[] getSync(GraphicsObject gro) {
		write.writePoint("pos", gro.node.pos);
		write.writeFloat("angle", gro.node.apos);
		write.writeFloat("colR", gro.color.r);
		write.writeFloat("colG", gro.color.g);
		write.writeFloat("colB", gro.color.b);
		write.writeFloat("colA", gro.color.a);
		return write.getData();
	}
	public static void fromSync(GraphicsObject gro, byte data[]) {
		read.setData(data);
		gro.node.pos = read.readPoint("pos");
		gro.node.apos = read.readFloat("angle");
		gro.color.r = read.readFloat("colR");
		gro.color.g = read.readFloat("colG");
		gro.color.b = read.readFloat("colB");
		gro.color.a = read.readFloat("colA");
	}
}
